<?php

include_once("../includes/jpGraphFunctions.php");
date_default_timezone_set("Asia/Kolkata");

// Sanity Check
if(!isset($_GET['yaxis']) || !isset($_GET['xaxis'])) {
	//return;
}
$filename = (isset($_GET['file'])) ? $_GET['file']: NULL;
$yaxis = (isset($_GET['yaxis'])) ? $_GET['yaxis']: NULL;
$xaxis = (isset($_GET['xaxis'])) ? $_GET['xaxis']: NULL;
$ln1 = (isset($_GET['ln1'])) ? $_GET['ln1']:NULL;
$ln2 = (isset($_GET['ln2'])) ? $_GET['ln2']:NULL;
$ln3 = (isset($_GET['ln3'])) ? $_GET['ln3']:NULL;
$ln4 = (isset($_GET['ln4'])) ? $_GET['ln4']:NULL;
$title = (isset($_GET['title'])) ? $_GET['title'] : "";
$type = (isset($_GET['type'])) ? $_GET['type'] : "linear";
$width=isset($_REQUEST['width'])?$_REQUEST['width']:NULL;
$height=isset($_REQUEST['height'])?$_REQUEST['height']:NULL;

$yaxis = json_decode($yaxis);
$xaxis = json_decode($xaxis);

// ToDo: Check is json_decode fails due to URL manipulation or other errors
 switch($type){
	case "linear":
		getGrahpAsImage($yaxis,$xaxis,$title);
	break;
		
	case "pie":
		getPieGrahpAsImage($xaxis,$yaxis,$title,$width,$height);
	break;
	
	case "multiline":
		if(isset($_REQUEST['file'])) {
			$filename = $_REQUEST['file'];
			$data = convertObjToArray(json_decode(file_get_contents("/home/indrajit/public_html/v1/graphdata/".$filename)));
			$ln1 = json_encode($data["ln1"]);
			$ln2 = json_encode($data["ln2"]);
			$ln3 = json_encode($data["ln3"]);
			$ln4 = json_encode($data["ln4"]);
			$xaxis = $data['xaxis'];
		}
		getMultilineGraphAsImage($ln1,$ln2,$ln3,$ln4,$xaxis,$title,$width=300,$height=200);
	break;
	
 }
?>









